import 'package:flutter/material.dart';
import 'package:flutter_study/simple_navigator.dart';
import 'package:flutter_study/param_navigator.dart';
import 'data_back_navigator.dart';

void main() => runApp(MyApp());

/*void main(){
  //runApp函数将根组件显示在屏幕上
  runApp(MyApp());
}*/

/*
//动态列表
void main() => runApp(
    DynamicListApp(items: List<String>.generate(20, (i) => "Item ${i}")));
*/

/**
 * 根组件
 */
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "MaterialApp title",
      home: FirstPageWidget(),
    );
  }
}


/**
 * Scaffold
 */
class ScaffoldWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //Scaffold：是Material中主要的布局组件
    return Scaffold(
      //appBar：在其Scaffold顶部显示一个应用栏
      appBar: AppBar(
        title: Text("Scaffold AppBar"),
      ),
      //body：显示主要内容,Center：使其子组件在中间位置
      body: Center(child: CardWidget()),
    );
  }
}

/**
 * 卡片式布局
 */
class CardWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Card(
      child: Column(
        children: <Widget>[
          ListTile(
            leading: Icon(Icons.account_box, color: Colors.lightBlue),
            title:
                Text("江苏省徐州市沛县", style: TextStyle(fontWeight: FontWeight.w500)),
            subtitle: Text("天奇：187****3450"),
          ),
          Divider(),
          ListTile(
            leading: Icon(Icons.account_box, color: Colors.lightBlue),
            title: Text("江苏省南京市江宁区",
                style: TextStyle(fontWeight: FontWeight.w500)),
            subtitle: Text("春运：153****5502"),
          ),
          Divider(),
          ListTile(
              leading: Icon(Icons.account_box, color: Colors.lightBlue),
              title: Text("浙江省杭州市余杭区",
                  style: TextStyle(fontWeight: FontWeight.w500)),
              subtitle: Text("传鹏：166****1218")),
          Divider()
        ],
      ),
    );
  }
}

/**
 * 层叠布局-层叠定位组件
 */
class StackPositionedWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Image.network(
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1569660771470&di=8d3c09e5830a1a5667b25385bdaacf20&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01b44b5d511452a8012187f4acf159.jpg%401280w_1l_2o_100sh.jpg"),
        Positioned(
            top: 10.0,
            left: 115.0,
            child: Container(
              child: Text("我命由我不由天",
                  style: TextStyle(fontSize: 30.0, color: Colors.red)),
            )),
        Positioned(
            top: 50.0,
            right: 20.0,
            child: Container(
              child: Text("坐北朝南吃西瓜皮朝东甩", style: TextStyle(fontSize: 20.0)),
              width: 20.0,
            )),
        Positioned(
            top: 50.0,
            left: 20.0,
            child: Container(
              child: Text("思前想后读左传页往右翻", style: TextStyle(fontSize: 20.0)),
              width: 20.0,
            ))
      ],
    );
  }
}

/**
 * 层叠布局
 */
class StackWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: FractionalOffset(0.9, 0.5),
      children: <Widget>[
        Image.network(
            "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1569660771470&di=8d3c09e5830a1a5667b25385bdaacf20&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01b44b5d511452a8012187f4acf159.jpg%401280w_1l_2o_100sh.jpg"),
        Container(
          child: Text("坐北朝南吃西瓜皮朝东甩", style: TextStyle(fontSize: 20.0)),
          width: 20.0,
        )
      ],
    );
  }
}

/**
 * 垂直布局
 */
class ColumnWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        RaisedButton(onPressed: () {}, color: Colors.red, child: Text('红色按钮')),
        RaisedButton(
          onPressed: () {},
          color: Colors.orange,
          child: Text('黄色大按钮'),
        ),
        RaisedButton(onPressed: () {}, color: Colors.pink, child: Text('粉色按钮'))
      ],
    );
  }
}

/**
 * 混合水平布局
 */
class RowMixWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        RaisedButton(onPressed: () {}, color: Colors.red, child: Text('红色按钮')),
        Expanded(
            child: RaisedButton(
          onPressed: () {},
          color: Colors.orange,
          child: Text('黄色按钮'),
        )),
        RaisedButton(onPressed: () {}, color: Colors.pink, child: Text('粉色按钮'))
      ],
    );
  }
}

/**
 * 灵活水平布局
 */
class RowExpandedWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        Expanded(
            child: RaisedButton(
                onPressed: () {}, color: Colors.red, child: Text('红色按钮'))),
        Expanded(
            child: RaisedButton(
          onPressed: () {},
          color: Colors.orange,
          child: Text('黄色按钮'),
        )),
        Expanded(
            child: RaisedButton(
                onPressed: () {}, color: Colors.pink, child: Text('粉色按钮')))
      ],
    );
  }
}

/**
 * 不灵活水平布局
 */
class RowWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        RaisedButton(onPressed: () {}, color: Colors.red, child: Text('红色按钮')),
        RaisedButton(
          onPressed: () {},
          color: Colors.orange,
          child: Text('黄色按钮'),
        ),
        RaisedButton(onPressed: () {}, color: Colors.pink, child: Text('粉色按钮'))
      ],
    );
  }
}

/**
 * 网格列表组件
 */
class GridViewWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GridView.count(
      padding: EdgeInsets.all(10.0),
      //网格间纵轴的间距
      mainAxisSpacing: 5.0,
      //网格间横轴的间距
      crossAxisSpacing: 5.0,
      //横轴每行网格总数
      crossAxisCount: 3,
      //网格宽高比
      childAspectRatio: 0.7,
      children: <Widget>[
        Image.network(
            "https://img.alicdn.com/bao/uploaded/i2/TB1yyzHe3mH3KVjSZKzXXb2OXXa_.jpg_300x300.jpg",
            fit: BoxFit.fill),
        Image.network(
            "https://img.alicdn.com/bao/uploaded/i1/TB1OqhKbrH1gK0jSZFwXXc7aXXa_.jpg_300x300.jpg",
            fit: BoxFit.fill),
        Image.network(
            "https://img.alicdn.com/bao/uploaded/i2/TB1LlFfhoH1gK0jSZSyXXXtlpXa_.jpg_300x300.jpg",
            fit: BoxFit.fill),
        Image.network(
            "https://img.alicdn.com/bao/uploaded/i4/TB1tf0XNlLoK1RjSZFuXXXn0XXa_.jpg_300x300.jpg",
            fit: BoxFit.fill),
        Image.network(
            "https://img.alicdn.com/bao/uploaded/i1/TB1FciZgAP2gK0jSZPxXXacQpXa_.jpg_300x300.jpg",
            fit: BoxFit.fill),
        Image.network(
            "https://img.alicdn.com/bao/uploaded/i4/TB1gyN4e7T2gK0jSZFkXXcIQFXa_.jpg_300x300.jpg",
            fit: BoxFit.fill),
        Image.network(
            "https://img.alicdn.com/bao/uploaded/i1/TB1mDwbgpT7gK0jSZFpXXaTkpXa_.jpg_300x300.jpg",
            fit: BoxFit.fill),
        Image.network(
            "https://img.alicdn.com/bao/uploaded/i4/TB1ULwZe4n1gK0jSZKPXXXvUXXa_.jpg_300x300.jpg",
            fit: BoxFit.fill),
        Image.network(
            "https://img.alicdn.com/bao/uploaded/i2/TB1mWpserj1gK0jSZFOXXc7GpXa_.jpg_300x300.jpg",
            fit: BoxFit.fill),
        Image.network(
            "https://img.alicdn.com/bao/uploaded/i3/TB1WWHHgUT1gK0jSZFhXXaAtVXa_.jpg_300x300.jpg",
            fit: BoxFit.fill),
      ],
    );
  }
}

/**
 * 图片组件
 */
class ImageWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        ListTile(
            title: Image(
                image: NetworkImage(
                    "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1569660771470&di=8d3c09e5830a1a5667b25385bdaacf20&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01b44b5d511452a8012187f4acf159.jpg%401280w_1l_2o_100sh.jpg")),
            subtitle: Text("ImageProvider")),
        ListTile(
            title: Image.asset("images/nz.jpg",
                color: Colors.greenAccent, colorBlendMode: BlendMode.darken),
            subtitle: Text("Image.asset")),
        ListTile(
            title: Image.network(
                "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1569660771470&di=8d3c09e5830a1a5667b25385bdaacf20&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01b44b5d511452a8012187f4acf159.jpg%401280w_1l_2o_100sh.jpg"),
            subtitle: Text("Image.network")),
      ],
    );
  }
}

/**
 * 动态列表组件
 */
class DynamicListApp extends StatelessWidget {
  final List<String> items;

  DynamicListApp({Key key, @required this.items}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "DynamicList",
      home: Scaffold(
        appBar: AppBar(
          title: Text("DynamicList"),
        ),
        body: Center(
            child: ListView.builder(
                itemCount: this.items.length,
                itemBuilder: (context, index) {
                  return ListTile(
                    title: Text("${items[index]}"),
                  );
                })),
      ),
    );
  }
}

/**
 * 横向列表
 */
class ListViewHorizontalWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //列表组件
    return ListView(
      //滚动方向
      scrollDirection: Axis.horizontal,
      children: <Widget>[
        Container(
          width: 180.0,
          color: Colors.lightBlue,
        ),
        Container(
          width: 180.0,
          color: Colors.amber,
        ),
        Container(
          width: 180.0,
          color: Colors.deepOrange,
        ),
        Container(
          width: 180.0,
          color: Colors.deepPurpleAccent,
        ),
      ],
    );
  }
}

/**
 * 列表组件
 */
class ListViewWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //列表组件
    return ListView(children: <Widget>[
      ListTile(
          leading: Icon(Icons.access_time), title: Text('access_time')),
      ListTile(
          leading: Icon(Icons.account_balance), title: Text('account_balance')),
    ]);
  }
}

/**
 * ListTile组件
 */
class ListTileWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListTile(
        //标题
        title: Text("House"),
        //副标题
        subtitle: Text("A House"),
        //前置图标
        leading: Icon(Icons.home),
        //后置图标
        trailing: Icon(Icons.keyboard_arrow_right),
        //内容内边距
        contentPadding: EdgeInsets.all(5.0),
        //是否选中状态
        selected: true);
  }
}

/**
 * 容器组件
 */
class ContainerWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //容器组件
    return Container(
      child: Text(
        "Hello World",
        style: TextStyle(fontSize: 40.0),
      ),
      width: 500.0,
      height: 400.0,
      //color: Colors.lightBlue,
      //字内容对齐方式
      alignment: Alignment.topLeft,
      //内边距
      padding: EdgeInsets.fromLTRB(10.0, 30.0, 0.0, 0.0),
      //外边距
      margin: EdgeInsets.all(10.0),
      //修饰器
      decoration: BoxDecoration(
          //背景渐变
          gradient: LinearGradient(
              colors: [Colors.lightBlue, Colors.greenAccent, Colors.purple]),
          //边框
          border: Border.all(width: 2.0, color: Colors.red),
          //边框圆角
          borderRadius: BorderRadius.all(Radius.circular(10.0))),
    );
  }
}

/**
 * 文本组件
 */
class TextWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //Text组件
    return Text(
        "2019年10月1日是中华人民共和国成立70周年纪念日。庆祝中华人民共和国成立70周年大会10月1日举行，习近平将发表重要讲话。庆祝大会后",
        //文本对齐方式
        textAlign: TextAlign.center,
        //最多显示行数
        maxLines: 2,
        //超出文本处理方式
        overflow: TextOverflow.ellipsis,
        //文本风格
        style: TextStyle(
            //字体大小
            fontSize: 25.0,
            //字体颜色
            //color: Color.fromARGB(255, 255, 0, 0),
            color: Colors.red,
            //修饰器
            decoration: TextDecoration.underline,
            //修饰风格
            decorationStyle: TextDecorationStyle.dashed));
  }
}
